function [Z, P, gain, order,Q, wn] = filter_chevyshev (filterType, aa, ap, wa, wp, waMENOS, waMAS, wpMENOS, wpMAS, order, Q)

%% calculo epsilon, n(si no fue espesificado) y a
epsilon=sqrt(10^(ap/10)-1);
wn=1;

    switch filterType
        case 2,
        wn=wa/wp;
        case 3,
        wn=wp/wa;
        case 1,
        wn=(waMAS-waMENOS)/(wpMAS-wpMENOS);
        case 4,
        wn=(wpMAS-wpMENOS)/(waMAS-waMENOS);
    end   
 if (order == 0) 
    epsilon=sqrt(10^(ap/10)-1);
    order=ceil(acosh(sqrt(10^(aa/10)-1)/epsilon)/acosh(wn));
 end
if (Q~=0)
    Q2=0;
    order=0;
    while (Q2 <= Q)
    order=order+1;
    Q2=(1/2)*sqrt(1+(1/(tan(pi*(2*order-1)/(2*order))*tan(asinh(1/epsilon)/order)))^2);
    end 
    order=order-1;
end

a=asinh(1/epsilon)/order;

%% inicializo variables
sigma=zeros(1,order);
w=zeros(1,order);


%% calculo polos
for k=1:order
    titas=(2*k-1)*pi/(2*order);
    sigma(k)=-sin(titas)*sinh(a);
    w(k)=cos(titas)*cosh(a);
end
w0=sqrt(sigma.*sigma + w.*w);

P=sigma+1i*w;

Q=abs(w0./(2*sigma));
gain=1; 
    for i=1:length(P)
        gain=gain*P(i);
        if gain==0 % si la constante se hace muy chica y MatLab redondea a cero la reinicio
            gain=1;
        end
    end
    gain=real(gain);
Z=[];
   
end